extends Spatial

onready var catalog = $prototypes/catalog
onready var Npc = $prototypes/npc
onready var map = $"../map"

var npcs = []
var shoppers = []

func _ready():
	pass

func generate_shoppers():
	var window_items = []
	var achievements = ["level_0"]
	var try_count = 0
	var generated = []
	while try_count < 500 and generated.size() < 3:
		var shopper = catalog.generate_npc(window_items, achievements)
		if shopper:
			var npc = Npc.duplicate()
			npc.spawn_shopper(shopper[0], shopper[1]) # TODO stop that array bullshit
			npc.astar = map.astar
			npc.transform.origin = map.door_position
			generated.append(npc)
			add_child(npc)
		try_count += 1
	print("generated shoppers", generated)
	shoppers = generated
	npcs.append_array(generated)

func next_shopper():
	var shopper = shoppers.pop_back()
	return shopper
